package com.controller.backend;

import com.biz.BillBiz;
import com.biz.WithdrawBillBiz;
import com.core.Result;
import com.core.ResultGenerator;
import com.entity.model.CustomerCommission;
import com.entity.model.WithdrawBill;
import com.github.pagehelper.PageInfo;
import com.util.webpage.PageData;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by jc on 2020/03/24.
 */
@Controller
@RequestMapping("/backend/security/withdrawBill")
public class WithdrawBillController extends BaseController<WithdrawBill> {
    @Autowired
    private WithdrawBillBiz withdrawBillBiz;
    @Autowired
    private BillBiz billBiz;

    @RequestMapping(value = "index")
    public String index() throws Exception {
        return "/backend/security/withdrawBill/list";
    }

    @RequestMapping(value = "detail")
    public String detail() throws Exception {
        return "/backend/security/withdrawBill/form";
    }

    @RequestMapping(value = "billList")
    public String billList() throws Exception {
        return "/backend/security/withdrawBill/billList";
    }


    @RequestMapping(value = "withdrawBillList")
    @ResponseBody
    public Result withdrawBillList(HttpServletRequest request) {
        PageData cond = new PageData(request);
        List<WithdrawBill> withdrawBills = withdrawBillBiz.withdrawBillList(cond);
        PageInfo<WithdrawBill> pageInfo = new PageInfo<WithdrawBill>(withdrawBills);
        Integer total = (int) pageInfo.getTotal();
        return ResultGenerator.genSuccessResult(withdrawBills,total);
    }

    @RequestMapping(value = "updateTradeNo")
    @ResponseBody
    public Result updateTradeNo(Integer id, String tradeNo) {
        WithdrawBill withdrawBill = new WithdrawBill();
        withdrawBill.setId(id);
        withdrawBill.setTradeNo(tradeNo);
        withdrawBill.setStatus(2);
        withdrawBillBiz.update(withdrawBill);

        billBiz.updateCommissionBillSuccess(withdrawBill.getId());
        return ResultGenerator.genSuccessResult();
    }

    @RequestMapping(value = "commissionFail")
    @ResponseBody
    public Result commissionFail(Integer id) {
        WithdrawBill withdrawBill = withdrawBillBiz.findById(id);
        withdrawBill.setStatus(3);
        withdrawBillBiz.update(withdrawBill);

        billBiz.updateCommissionBillFail(withdrawBill.getId());
        return ResultGenerator.genSuccessResult();
    }

    @RequestMapping(value = "vipPerformanceList")
    @ResponseBody
    public Result vipPerformanceList(HttpServletRequest request) {
        PageData cond = new PageData(request);

        List<WithdrawBill> list = withdrawBillBiz.vipPerformanceList(cond);
        PageInfo<WithdrawBill> pageInfo = new PageInfo<WithdrawBill>(list);
        Integer total = (int) pageInfo.getTotal();
        return ResultGenerator.genSuccessResult(list, total);
    }
}
